-
Notifications
You must be signed in to change notification settings - Fork 607
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix: Fix valset pref unbonding bugs #5967
Conversation
@stackman27 taking over this PR (or should I get this mergeable (just fixing conflicts), and then you implement the remainder in a followup? |
its okay i can just work on this PR and have 1 PR that fixes |
x/valset-pref/validator_set.go
Outdated
totalAmountFromWeights = totalAmountFromWeights.Add(val.Weight.Mul(tokenAmt)) | ||
} | ||
// Step 7 | ||
fmt.Println("Undelegating the remaining amount.") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
note: i'm a little worried about this part of the algorithm. would appreciate a thorough review here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Which part in specific are you worried about?
x/valset-pref/validator_set.go
Outdated
targetRatio := sdk.OneDec() | ||
amountRemaining := coin.Amount | ||
|
||
fmt.Println("VRATIO PRE: ", valSetRatio) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
note: these Println are easier to debug/review. Will remove them once this PR is close to merge
x/valset-pref/README.md
Outdated
Algorithm for undelegation; | ||
// unbond as true to valset ratios as possible. Undelegation should be possible. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should add my intuition description for the algorithm back!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a reason all of this is commented?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@czarcas7ic this was just the pseudocode. I wrote the algorithm here: https://github.com/osmosis-labs/osmosis/pull/5967/files#diff-4422f5e761e99a0e29d2ba7017ece4aa6b486b5ee24b18fb58fcbc9c26a8e7a6R133
following the steps
x/valset-pref/validator_set.go
Outdated
// Step 1-2 | ||
var valSetRatio []ValRatio |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why did we remove the helper I had before? It improves gas costs by removing repeated Get's with GetDelegationPreferences, and makes this main function cleaner?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i did this for couple of reason
- the helper func was useful except i wanted current delegations to be represented as valset {valAddr, weight} and the helper func did the opposite. (represented valset as current delegation)
- I checked the flow and current func i'm using has less Get calls to staking keeper than the helper function.
(helper = getValset -> if exist -> getDelegation -> else -> GetDelegatorDelegation,
nonHelper = getValSet -> if exist return -> else -> GetDelegatorDelegations)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah interesting, didn't notice the delegations call being reused my bad
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Err, the delegations aren't getting reused rightnow if you don't have a validator set. This is causing more gas usage.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if you dont have a validator set but have existing delegations we create a validator set for you with existing delegations
ref: https://github.com/osmosis-labs/osmosis/pull/5967/files#diff-eca64719739dd13c273495f6d28e8da96083fdf0c629da0eef1a22206839ed24R84
note: we create temporary valset but donot store it in state, to store it in state you just call SetValSetPref
. If valSet exist and delegation also exist and you want to store temporary valset in state this implies ValSetRedelegation
devbot add changelog fix ValSet undelegate API out of sync with existing staking |
@ValarDragon i'm a little worried that we might have this issue in redelegation too, since it requires tokens to be unbonded. I haven't dug deep into it but if you think dont think this is the case i can focus on other work |
Status update: Working on a PR for improvising test cases and refactoring, will get is in as Korean Holidays are over! |
* Add Test cases and fix * Update x/valset-pref/keeper.go * Adams comment * add error types and tidy test --------- Co-authored-by: Adam Tucker <[email protected]> Co-authored-by: Adam Tucker <[email protected]>
I looked over this again, and everything except for not being able to reach steps 5-7 makes sense to me. Once we get an answer to this as well as tests if it is in fact reachable, I can approve |
* initial push * add todo * msg server test * add godoc * custom error * update godoc * update proto and remove duplication * add more TODOs * use min when calculating amt to withdraw from last val
for _, existingDelegation := range delegations { | ||
totalShares = totalShares.Add(existingDelegation.Shares) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wait... is this the code for valset preference? I think this is fundamentally wrong. This needs to be based on the token amount, not the number of shares
I think the last bug should be fixed, but in a separate PR. Otw this PR looks good to go to me |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed with merging this and fixing the share-based issue in a separate PR
* Add helper to get existing delegations along with valset pref * Lay out more of the logic nuance * Add pseudo-code needed * algorithm v1 * added algorithm docs * fixed all test * removed unwanted files * remove more code * added more tests * update changelog * added test and addressed feedback * Update x/valset-pref/validator_set.go * Update x/valset-pref/validator_set.go * Update x/valset-pref/README.md * Minor cleanup * re-use validator gets * Refactor * Highlight bug * fixed the issue * added comments * update changelog * fixed the issue * fixed go test * fixed test * lint * Finish ValSet Pref Unbonding (#6630) * Add Test cases and fix * Update x/valset-pref/keeper.go * Adams comment * add error types and tidy test --------- Co-authored-by: Adam Tucker <[email protected]> Co-authored-by: Adam Tucker <[email protected]> * feat: unbond with rebalanced val set weights (#6685) * initial push * add todo * msg server test * add godoc * custom error * update godoc * update proto and remove duplication * add more TODOs * use min when calculating amt to withdraw from last val * Update x/valset-pref/validator_set.go --------- Co-authored-by: stackman27 <[email protected]> Co-authored-by: devbot-wizard <[email protected]> Co-authored-by: Adam Tucker <[email protected]> Co-authored-by: roman <[email protected]> Co-authored-by: Matt, Park <[email protected]> Co-authored-by: Adam Tucker <[email protected]> (cherry picked from commit e12011b)
* Add helper to get existing delegations along with valset pref * Lay out more of the logic nuance * Add pseudo-code needed * algorithm v1 * added algorithm docs * fixed all test * removed unwanted files * remove more code * added more tests * update changelog * added test and addressed feedback * Update x/valset-pref/validator_set.go * Update x/valset-pref/validator_set.go * Update x/valset-pref/README.md * Minor cleanup * re-use validator gets * Refactor * Highlight bug * fixed the issue * added comments * update changelog * fixed the issue * fixed go test * fixed test * lint * Finish ValSet Pref Unbonding (#6630) * Add Test cases and fix * Update x/valset-pref/keeper.go * Adams comment * add error types and tidy test --------- Co-authored-by: Adam Tucker <[email protected]> Co-authored-by: Adam Tucker <[email protected]> * feat: unbond with rebalanced val set weights (#6685) * initial push * add todo * msg server test * add godoc * custom error * update godoc * update proto and remove duplication * add more TODOs * use min when calculating amt to withdraw from last val * Update x/valset-pref/validator_set.go --------- Co-authored-by: stackman27 <[email protected]> Co-authored-by: devbot-wizard <[email protected]> Co-authored-by: Adam Tucker <[email protected]> Co-authored-by: roman <[email protected]> Co-authored-by: Matt, Park <[email protected]> Co-authored-by: Adam Tucker <[email protected]> (cherry picked from commit e12011b) Co-authored-by: Dev Ojha <[email protected]>
* Add helper to get existing delegations along with valset pref * Lay out more of the logic nuance * Add pseudo-code needed * algorithm v1 * added algorithm docs * fixed all test * removed unwanted files * remove more code * added more tests * update changelog * added test and addressed feedback * Update x/valset-pref/validator_set.go * Update x/valset-pref/validator_set.go * Update x/valset-pref/README.md * Minor cleanup * re-use validator gets * Refactor * Highlight bug * fixed the issue * added comments * update changelog * fixed the issue * fixed go test * fixed test * lint * Finish ValSet Pref Unbonding (#6630) * Add Test cases and fix * Update x/valset-pref/keeper.go * Adams comment * add error types and tidy test --------- Co-authored-by: Adam Tucker <[email protected]> Co-authored-by: Adam Tucker <[email protected]> * feat: unbond with rebalanced val set weights (#6685) * initial push * add todo * msg server test * add godoc * custom error * update godoc * update proto and remove duplication * add more TODOs * use min when calculating amt to withdraw from last val * Update x/valset-pref/validator_set.go --------- Co-authored-by: stackman27 <[email protected]> Co-authored-by: devbot-wizard <[email protected]> Co-authored-by: Adam Tucker <[email protected]> Co-authored-by: roman <[email protected]> Co-authored-by: Matt, Park <[email protected]> Co-authored-by: Adam Tucker <[email protected]>
Closes: #6028
This PR is aiming to fix the following two bugs in valset-preference unbonding:
The solution to both is the same: Get the delegator's existing delegation to each val in valset, which does increase gas.